#set( $symbol_pound = '#' )
#set( $symbol_dollar = '$' )
#set( $symbol_escape = '\' )
package ${package}.device.mqtt.consume;

import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.integration.acks.SimpleAcknowledgment;
import org.springframework.integration.annotation.ServiceActivator;
import org.springframework.messaging.Message;
import org.springframework.stereotype.Service;

@Service
@Slf4j
@ConditionalOnProperty(prefix = "mqtt", name = "enable", havingValue = "true")
public class MqttListener {
    @ServiceActivator(inputChannel = "mqttInputExecutorChannel")
    public void receiveMessage(Message<?> message) {
        SimpleAcknowledgment acknowledgmentCallback = (SimpleAcknowledgment) message.getHeaders()
                .get("acknowledgmentCallback");
        acknowledgmentCallback.acknowledge();
        log.info("receiveMessage: payload={},  topic={}", JSON.toJSONString(message.getPayload()));
    }
}
